package me.sealer.jmx.mbean;

import me.sealer.jmx.entity.QueueInfo;

import javax.management.MXBean;
import java.util.Date;
import java.util.Queue;

/**
 * @author sealer
 * @date 2018/01/19.
 */
@MXBean
public class QueueInspector implements QueueInspectorMXBean {
    private Queue<String> queue;

    public QueueInspector(Queue<String> queue) {
        this.queue = queue;
    }

    @Override
    public QueueInfo getQueueInfo() {
        synchronized (queue) {
            return new QueueInfo(new Date(), queue.size(), queue.peek());
        }
    }

    @Override
    public void clearQueue() {
        synchronized (queue) {
            queue.clear();
        }
    }
}
